import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.ListIterator;

import javax.swing.JPanel;

class HashPanel extends JPanel {
	ArrayList<Quad> quads;
	//ArrayList<Quad> quad_val;
	Color  quadRGB;
	final int radius = 20;
	private MyHashTable<String, String> hash;
	
	public HashPanel( MyHashTable<String, String> h)
	{
		this.hash = h;
		quadRGB = new Color(255, 0,0);
	}
	
	public void setHash(MyHashTable<String, String> h) 
	{
		hash = h;
	}
	
	
	public void paint (Graphics g)
	{
	    super.paint(g);
	    
	    g.setColor (Color.black);
	    g.drawRect (0,0, getWidth(),getHeight());//Border
	    quads = new ArrayList<Quad>(hash.arr_size());
	    //quad_val = new ArrayList<Quad>(hash.size());
	    for(int i = 0; i < hash.arr_size(); i++)
	    {
	    	int y0 = 5+i*20;
	    	int x =  getWidth()/4;
	    	quads.add(new Quad(x,y0,radius, quadRGB));
	    	quads.get(i).draw(g);
	    	if (hash.getBucketArray()[i]!= null)
	    	{
	    		ListIterator  iterator = hash.getBucketArray()[i].listIterator();
	    		int x0 = x + radius;
	    		while(iterator.hasNext())
	    		{
	    			MyHashEntry<String,String> current = ((MyHashEntry<String, String>) iterator.next());
	    			g.drawLine(x0,y0+radius/2,x0+radius,y0+radius/2);
	    			
	    			String nod_str = " ("+current.getKey().toString()+", "+
	    					current.getValue().toString()+") "; 
	    			
	    			x0+= radius;
	    			
	    			g.drawString(nod_str, x0, y0 + radius/2);
	    			//Quad node = new Quad(x0+radius,y0,radius,quadRGB);
	    			//quad_val.add(node);
	    			x0+= 5*nod_str.length();
	    		}
	    	}
	    }
	} 
}